package models

import (
	"chat/utils"
	"gorm.io/gorm"
)

type Notice struct {
	gorm.Model
	Content string `json:"content" gorm:"公告内容"`
	OwnerId uint   `json:"owner_id" gorm:"所属群"`
}

func (table *Notice) TableName() string {
	return "notice_basic"
}

func CreateNotice(notice *Notice) error {
	return utils.Mysql.Table("notice_basic").Create(notice).Error
}

func GetNoticeList(id string) ([]*Notice, error) {
	notices := make([]*Notice, 0)
	if err := utils.Mysql.Table("notice_basic").
		Where("owner_id = ?", id).
		Find(&notices).Error; err != nil {
		return nil, err
	}
	return notices, nil
}

func DeleteNotice(id uint) error {
	return utils.Mysql.Table("notice_basic").Where("id = ?", id).Delete(&Notice{}).Error
}
